package vcp.views;

import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.event.AncestorListener;

import db.parking.beans.ParkingLot;
import vcp.application.UserManagement;
import vcp.common.AbstractView;
import vcp.common.IView;
import vcp.controllers.SaveParkingController;
import vcp.gui.panels.PnlParkingGrid;
import vcp.gui.panels.PnlSaveParking;




/**
 * SaveParking View
 *
 */
public class SaveParkingView extends AbstractView implements Observer, IView {
	private PnlSaveParking saveParkingPanel;
	PnlParkingGrid pgrid;
	SaveParkingController controller;

	public SaveParkingView() {
		saveParkingPanel = new PnlSaveParking();

	}

	@Override
	public void addController(Object obj) {
		this.saveParkingPanel.addAncestorListener((AncestorListener) obj);
		this.saveParkingPanel.getComboLevel().addActionListener(
				(ActionListener) obj);
		this.saveParkingPanel.getComboLevel().setActionCommand("levelChoice");
		this.controller = (SaveParkingController) obj;
	}

	@Override
	public void update(Observable arg, Object obj) {
		    ParkingLot pl = (ParkingLot) obj;		
			saveParkingPanel.getPnlLotGrid().removeAll();
			pgrid = new PnlParkingGrid(pl, controller);
			saveParkingPanel.getPnlLotGrid().add(pgrid);
			saveParkingPanel.getParentFrame().pack();
	}

	public PnlSaveParking getSaveParkingPanel() {
		return saveParkingPanel;
	}

}
